using System;

using SBPweb.Common.Session;

namespace SBPweb.PROvibe.Business.Logic
{

	public class SiteManager
	{

		private static string SESSIONKEY_CURRENT_SITE = "_SiteManager.Site";

		#region Constructor logic

		private SiteManager()
		{
		}

		#endregion

		public static Entities.Site CurrentSite
		{
			get
			{
				string key = string.Format("{0}:{1}", SESSIONKEY_CURRENT_SITE, RequestManager.HttpHost);
				Entities.Site site = SessionHandler.Get<Entities.Site>(key);

				if (site == null)
				{
					site = Business.Warehouse.SiteFactory.ReadSiteByHost(RequestManager.HttpHost);
					SessionHandler.Put<Entities.Site>(key, site);
				}

				return site;
			}
		}

		public static void MaintainSite()
		{
			ThemeManager.SelectedTheme = CurrentSite.Theme.Name;
		}

		public class SiteNotFoundException : Exception
		{

			public SiteNotFoundException(string host)
				: base(string.Format("Site referer {0} could not be found in database!", host))
			{
			}

		}
	}
}